// package headfirst.designpatterns.observer.weather;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ForecastDisplay implements ActionListener, DisplayElement {
	private float currentPressure = 29.92f;  
	private float lastPressure;
	// private WeatherData weatherData;
	@Override
	public void actionPerformed(ActionEvent event) {
		WeatherData wd = (WeatherData)(event.getSource());
		update(wd.getTemperature(), wd.getHumidity(), wd.getPressure());
	}
	public ForecastDisplay(WeatherData weatherData) {
		// this.weatherData = weatherData;
		// weatherData.registerObserver(this);
		weatherData.addActionListener(this);
	}

	public void update(float temp, float humidity, float pressure) {
        lastPressure = currentPressure;
		currentPressure = pressure;

		display();
	}

	public void display() {
		System.out.print("Forecast: ");
		if (currentPressure > lastPressure) {
			System.out.println("Improving weather on the way!");
		} else if (currentPressure == lastPressure) {
			System.out.println("More of the same");
		} else if (currentPressure < lastPressure) {
			System.out.println("Watch out for cooler, rainy weather");
		}
	}
}
